package modelo.mensajes;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public abstract class Mensaje {
	
	protected String tipo;
	protected int    id_msj;
	protected int    id_origen;
	protected String cuerpo = "";
	
	public abstract int 	getID();
	public abstract int 	getIDorigen();
	public abstract String 	getCuerpo();
	
	public abstract void 	setID(int id_msj);
	public abstract void 	setIDorigen(int id);
	public abstract void 	setCuerpo(String cuerpo);
	
	public byte[] toByte() throws IOException {
		ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
		DataOutputStream out = new DataOutputStream(byteStream);
	
		out.writeUTF("SAER");
		out.writeUTF(tipo);
		out.writeInt(id_msj);  	 // ID msj
		out.writeInt(id_origen);	 // ID cap
		out.writeUTF(cuerpo);
		
		out.flush();
		out.close();
		
		return byteStream.toByteArray();
	}
}
